package initialize

import (
	"fmt"
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)

//@author: SliverHorn
//@function: Gorm
//@description: 初始化数据库并产生数据库全局变量
//@return: *gorm.DB

// Gorm 初始化数据库并产生数据库全局变量
func Gorm() *gorm.DB {
	return GormSqlite()
}

// MysqlTables
//@author: SliverHorn
//@function: MysqlTables
//@description: 注册数据库表专用
//@param: db *gorm.DB
//
//func MysqlTables(db *gorm.DB) {
//	err := db.AutoMigrate(
//		model.SysUser{},
//		model.SysAuthority{},
//		model.SysApi{},
//		model.SysBaseMenu{},
//		model.SysBaseMenuParameter{},
//		model.JwtBlacklist{},
//		model.SysDictionary{},
//		model.SysDictionaryDetail{},
//		model.ExaFileUploadAndDownload{},
//		model.ExaFile{},
//		model.ExaFileChunk{},
//		model.ExaSimpleUploader{},
//		model.ExaCustomer{},
//		model.SysOperationRecord{},
//
//		// Code generated by gin-vue-admin Begin; DO NOT EDIT.
//		model.Items{},
//		// Code generated by gin-vue-admin End; DO NOT EDIT.
//	)
//	if err != nil {
//		global.GVA_LOG.Error("register table failed", zap.Any("err", err))
//		os.Exit(0)
//	}
//	global.GVA_LOG.Info("register table success")
//}

//
//@author: SliverHorn
//@function: GormMysql
//@description: 初始化Mysql数据库
//@return: *gorm.DB

func GormSqlite() *gorm.DB {
	if db, err := gorm.Open(sqlite.Open("black_mamba_db.db"), &gorm.Config{}); err != nil {
		//global.GVA_LOG.Error("Sqlite启动异常", zap.Any("err", err))
		//os.Exit(0)
		//return nil
		fmt.Println("Sqlite启动异常")
		return nil
	} else {
		return db
	}
}
